package core;

import Utils.tempWorkTree;
import fileoperation.FileReader;
import gitobject.Commit;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class JitLog {

    public static void log() throws IOException {
        tempWorkTree.updateWorkTree();
        //根据headKey得到tempcommit
        String headKey= Commit.getLastCommit();
        Commit tempcommit = Commit.deserialize(headKey);
        while(tempcommit!=null){
            System.out.println(tempcommit); //打印信息
            tempcommit=Commit.deserialize(tempcommit.getParent());
        }
    }

    public static void reflog() throws IOException {
        tempWorkTree.updateWorkTree();
        List<String> allLines = Files.readAllLines(Paths.get(tempWorkTree.logHead));
        for (String allLine : allLines) {
            System.out.println(allLine);
        }
    }
}
